<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
</head>
<body>
<div id="vuebox">
    <div class="container" style="margin-top: 50px">
        <div class="row">
            <div class="col-md-6">
                <form class="form-inline" role="form" style="padding-left: 250px;">
                    <div class="form-group" style="padding-left: 20px;">
                        <label>按区域查询:</label>
                        <select class="form-control" v-model="districtId">
                            <option value="0">全部</option>
                            <option v-for="item in districtList.data" :value="item.id">{{item.name}}</option>
                        </select>
                    </div>
                    <div class="form-group" style="padding-left: 20px;">
                        <button type="button" class="btn btn-primary" @click="selectQuality(1)">查询</button>
                    </div>

                </form>

            </div>
            <div class="col-md-4 text-right">
                <a href="add_entry.html" class="btn btn-primary">添加空气质量信息</a>
            </div>
        </div>

        <br/>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>区域</th>
                <th>检测时间</th>
                <th>PM10数据</th>
                <th>PM2.5数据</th>
                <th>监测站</th>
                <!--<th>操作</th>-->
            </tr>
            </thead>
            <tbody>
            <tr v-for="item in entries.data.list">
                <td>{{item.districtid}}</td>
                <td>{{item.monitortime}}</td>
                <td>{{item.pm10}}</td>
                <td>{{item.pm25}}</td>
                <td>{{item.monitoringstation}}</td>
                <!--<td>-->
                    <!--<button class="btn btn-success" @click="to_update_entry(item.id)">修改</button>-->
                    <!--<button class="btn btn-danger" @click="deleteEntry(item.id)">删除</button>-->
                <!--</td>-->
            </tr>
            </tbody>
        </table>
        <br/>
        <div class="text-center">
           <ul class="pagination">
               <li v-show="entries.data.hasPreviousPage">
                   <a href="#" @click.stop="selectQuality(entries.data.prePage)">&laquo;</a>
               </li>
               <li :class="{active:!entries.data.pageNum==i}" v-for="i in entries.data.navigatepageNums">
                   <a href="#" @click.stop="selectQuality(i)">{{i}}</a>
               </li>
               <li v-show="entries.data.hasNextPage">
                   <a href="#" @click.stop="selectQuality(entries.data.nextPage)">&raquo;</a>
               </li>
           </ul>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
    var vm = new Vue({
        el: "#vuebox",
        data: {
            districtList: {},
            districtId: "0",
            entries: {}
        },
        methods: {
            selectQuality: function (pageNum) {
                axios.get("/selectQuality", {
                    params: {
                        districtId: this.districtId,
                        pageNum: pageNum
                    }
                }).then(res => this.entries = res.data);
            }
        },
        mounted() {
            axios.get("/getDistrictList").then(res => this.districtList = res.data);
            this.selectQuality(1);
        }
    });


</script>